<template>
  <div>
    <!-- 标题 -->
    <div class="settitle">
      <div class="setimg" @click="$router.back()">
        <img src="../assets/imgs/iconse/左箭头.png" alt="" />
      </div>
      <div class="text"><h2>求职意向</h2></div>
    </div>

    <div class="item" v-for="item in datalist" :key="item.id">
      <div class="title">
        <span>{{ item.title }}</span>
      </div>
      <div class="text" v-if="item.flag">
        <div class="box" v-for="(item, index) in item.item" :key="index">
          <p>{{ item.title }}</p>
          <span @click="getname(index)">{{ item.name }}</span>
        </div>
      </div>
      <div class="text" v-if="!item.flag">
        <span>{{ item.item }}</span>
      </div>
    </div>

    <input
      type="text"
      class="edit"
      v-model="val"
      v-show="show"
      @keydown.enter="add(val)"
      @keydown.esc="esc"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {
      val: "",
      show: false,
      ids: 0,
      datalist: [
        {
          id: "1",
          title: "当前状态",
          item: "学生",
          flag: false,
        },
        {
          id: "2",
          title: "求职方向",
          item: [
            {
              title: "期望行业",
              name: "不限",
            },
            {
              title: "职位类型",
              name: "web前端",
            },
            {
              title: "意向城市",
              name: "东莞",
            },
          ],
          flag: true,
        },
      ],
    };
  },
  methods: {
    getname(index) {
      this.show = true;
      this.ids = index;
      this.val = this.datalist[1].item[this.ids].name;
      console.log(index);
    },
    eeg(event) {
      this.val = event.target.innerHTML;
    },
    add(val) {
      this.datalist[1].item[this.ids].name = val;
      this.val = "";
      this.show = false;
      console.log(val);
    },
    esc() {
      this.val = "";
      this.show = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.edit {
  position: absolute;
  width: 80%;
  height: 40px;
  right: 0px;
  left: 0px;
  margin: 50px auto;
  background-color: #fff;
  font-size: 22px;
  text-indent: 1em;
  border: 0px;
  border-radius: 20px;
  box-shadow: 0px 0px 8px #ccc;
}
.settitle {
  height: 60px;
  display: flex;
  align-items: center;
  background-color: #fff;
  box-shadow: 0px 0px 0px 1px rgba($color: #cccc, $alpha: 0.4);
  .setimg {
    height: 18px;
    position: absolute;
    left: 15px;
    img {
      height: 100%;
      display: block;
    }
  }
  .text {
    margin: 0 auto;
  }
}

.item {
  box-sizing: border-box;
  padding: 0px 20px;
  .title {
    height: 70px;
    line-height: 70px;
    font-size: 20px;
    font-weight: 800;
  }
  .text {
    .box {
      height: 70px;
      margin-bottom: 16px;
      p {
        text-indent: 10px;
        color: #333;
      }
      span {
        border-bottom: 1px solid #ccc;
        height: 50px;
        line-height: 50px;
        font-size: 19px;
        text-indent: 10px;
        display: block;
        position: relative;
        &::after {
          content: "";
          display: block;
          position: absolute;
          height: 26px;
          width: 13px;
          background: url(../assets/imgs/右箭头.png) no-repeat center;
          background-size: 100%;
          top: 0px;
          bottom: 0px;
          right: 0px;
          margin: auto 0px;
        }
      }
    }
    span {
      border-bottom: 1px solid #ccc;
      height: 70px;
      line-height: 70px;
      font-size: 19px;
      text-indent: 10px;
      display: block;
      margin-bottom: 10px;
      position: relative;
      &::after {
        content: "";
        display: block;
        position: absolute;
        height: 26px;
        width: 13px;
        background: url(../assets/imgs/右箭头.png) no-repeat center;
        background-size: 100%;
        top: 0px;
        bottom: 0px;
        right: 0px;
        margin: auto 0px;
      }
    }
  }
}
</style>